package com.hqyj.mana.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hqyj.mana.dao.BasicInformationMapper;
import com.hqyj.mana.dao.HrManagementMapper;
import com.hqyj.mana.pojo.BasicInformation;
import com.hqyj.mana.pojo.HrManagement;
import com.hqyj.mana.service.PositionService;
@Service
public class PositionServiceImpl implements PositionService {
	@Autowired
	private HrManagementMapper hrManagementMapper;
	@Autowired
	private BasicInformationMapper basicInformationMapper;
	@Override
	public List<HrManagement> selectAllHrManagement(String id) {
		// TODO Auto-generated method stub
		System.out.println(id);
		List<HrManagement> list= hrManagementMapper.selectAll(id);
		return list;
	}

	@Override
	@Transactional
	public boolean add(HrManagement hr) {
		// TODO Auto-generated method stub
		BasicInformation basicInformation= basicInformationMapper.selectByPrimaryKey(hr.getId());
		String originalPost = basicInformation.getPost();
		basicInformation.setPost(hr.getPost());
		basicInformationMapper.updateByPrimaryKeySelective(basicInformation);
		Date date = new Date();
		SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd :hh:mm:ss");
		hr.setOriginalPost(originalPost);
		hr.setName(basicInformation.getName());
		hr.setTransferTime(dateFormat.format(date));
		int result = hrManagementMapper.insertSelective(hr);
		if(result==0){
			return false;
		}
		return true;
	}

	@Override
	public boolean del(Integer id) {
		// TODO Auto-generated method stub
		int result = hrManagementMapper.deleteByPrimaryKey(id);
		if(result==0){
			return false;
		}
		return true;
	}
	
}
